/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * humanResourceModule.java
 *
 * Created on Oct 22, 2010, 4:20:08 PM
 */

package restaurantmanagementsystem;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.*;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author edwind
 */
public class humanResourceModule extends javax.swing.JFrame {

    /** Creates new form humanResourceModule */
    public humanResourceModule() {
        super("Human Resources");
        initComponents();
        initDatabase();

        this.setSize(850, 630);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension windowSize = this.getSize();

        int windowX = Math.max(0, (screenSize.width  - windowSize.width ) / 2);
        int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2);

        this.setLocation(windowX, windowY);
        this.setResizable(false);

        getTableInfo();
        employeeButton.setSelected(true);
        table1.requestFocus();
        setTable();
        disableSaveAndUndoButton();
        employeePanel.setVisible(false);
        jobPanel.setVisible(false);
        branchPanel.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        mainLayeredPane = new javax.swing.JLayeredPane();
        mainPanel = new javax.swing.JPanel();
        toolbarPanel = new javax.swing.JPanel();
        toolbar1 = new javax.swing.JToolBar();
        buttonNew = new javax.swing.JButton();
        buttonEdit = new javax.swing.JButton();
        buttonSave = new javax.swing.JButton();
        butttonDelete = new javax.swing.JButton();
        toolbar2 = new javax.swing.JToolBar();
        buttonLogout = new javax.swing.JButton();
        buttonExit = new javax.swing.JButton();
        scrollPane = new javax.swing.JScrollPane();
        table1 = new javax.swing.JTable();
        topPanel = new javax.swing.JPanel();
        toolbar3 = new javax.swing.JToolBar();
        employeeButton = new javax.swing.JRadioButton();
        jobButton = new javax.swing.JRadioButton();
        branchButton = new javax.swing.JRadioButton();
        toolbar4 = new javax.swing.JToolBar();
        searchButton = new javax.swing.JButton();
        searchField = new javax.swing.JTextField();
        bottomPanel = new javax.swing.JPanel();
        buttonPanel = new javax.swing.JPanel();
        saveButton2 = new javax.swing.JButton();
        undoButton = new javax.swing.JButton();
        panel = new javax.swing.JPanel();
        employeePanel = new javax.swing.JPanel();
        labelName = new javax.swing.JLabel();
        labelJob = new javax.swing.JLabel();
        labelBranch = new javax.swing.JLabel();
        labelContactNumber = new javax.swing.JLabel();
        labelAddress = new javax.swing.JLabel();
        labelEqual1 = new javax.swing.JLabel();
        labelEqual2 = new javax.swing.JLabel();
        labelEqual3 = new javax.swing.JLabel();
        labelEqual4 = new javax.swing.JLabel();
        labelEqual5 = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        contactNumberField = new javax.swing.JTextField();
        addressField1 = new javax.swing.JTextField();
        addressField2 = new javax.swing.JTextField();
        jobDropDownMenu = new javax.swing.JComboBox();
        branchDropDownMenu = new javax.swing.JComboBox();
        labelName1 = new javax.swing.JLabel();
        labelEqual12 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        branchPanel = new javax.swing.JPanel();
        branchNoLabel = new javax.swing.JLabel();
        branchNameLabel = new javax.swing.JLabel();
        branchAddressLabel = new javax.swing.JLabel();
        branchNoField = new javax.swing.JTextField();
        branchNameField = new javax.swing.JTextField();
        branchAddressField1 = new javax.swing.JTextField();
        branchAddressField2 = new javax.swing.JTextField();
        labelEqual9 = new javax.swing.JLabel();
        labelEqual10 = new javax.swing.JLabel();
        labelEqual11 = new javax.swing.JLabel();
        jobPanel = new javax.swing.JPanel();
        jobNoLabel = new javax.swing.JLabel();
        jobNameLabel = new javax.swing.JLabel();
        salaryLabel = new javax.swing.JLabel();
        labelEqual6 = new javax.swing.JLabel();
        labelEqual7 = new javax.swing.JLabel();
        labelEqual8 = new javax.swing.JLabel();
        jobNoField = new javax.swing.JTextField();
        jobNameField = new javax.swing.JTextField();
        salaryField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        mainPanel.setBackground(new java.awt.Color(175, 170, 165));
        mainPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        toolbarPanel.setBorder(null);
        toolbarPanel.setOpaque(false);

        toolbar1.setFloatable(false);
        toolbar1.setOrientation(1);
        toolbar1.setRollover(true);
        toolbar1.setOpaque(false);

        buttonNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new.png"))); // NOI18N
        buttonNew.setText("New");
        buttonNew.setToolTipText("Add a new record");
        buttonNew.setFocusable(false);
        buttonNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNew.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonNew.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonNew.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNew.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonNewMouseClicked(evt);
            }
        });
        toolbar1.add(buttonNew);

        buttonEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit.png"))); // NOI18N
        buttonEdit.setText("Edit");
        buttonEdit.setToolTipText("Edit a record");
        buttonEdit.setFocusable(false);
        buttonEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonEdit.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonEdit.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonEdit.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEdit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonEditMouseClicked(evt);
            }
        });
        toolbar1.add(buttonEdit);

        buttonSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.png"))); // NOI18N
        buttonSave.setText("Save");
        buttonSave.setToolTipText("Save all changes");
        buttonSave.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        buttonSave.setFocusable(false);
        buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonSave.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonSave.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonSave.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonSaveMouseClicked(evt);
            }
        });
        toolbar1.add(buttonSave);

        butttonDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        butttonDelete.setText("Delete");
        butttonDelete.setToolTipText("Delete a record");
        butttonDelete.setFocusable(false);
        butttonDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        butttonDelete.setMaximumSize(new java.awt.Dimension(62, 66));
        butttonDelete.setMinimumSize(new java.awt.Dimension(62, 66));
        butttonDelete.setPreferredSize(new java.awt.Dimension(62, 66));
        butttonDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        butttonDelete.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                butttonDeleteMouseClicked(evt);
            }
        });
        toolbar1.add(butttonDelete);

        toolbar2.setFloatable(false);
        toolbar2.setOrientation(1);
        toolbar2.setRollover(true);
        toolbar2.setOpaque(false);

        buttonLogout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logout (1).png"))); // NOI18N
        buttonLogout.setText("Logout");
        buttonLogout.setToolTipText("Log out from your account");
        buttonLogout.setFocusable(false);
        buttonLogout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonLogout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonLogout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonLogoutMouseClicked(evt);
            }
        });
        toolbar2.add(buttonLogout);

        buttonExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit2.png"))); // NOI18N
        buttonExit.setText("Exit");
        buttonExit.setToolTipText("Close the program");
        buttonExit.setFocusable(false);
        buttonExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonExit.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonExit.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonExit.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonExit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonExitMouseClicked(evt);
            }
        });
        toolbar2.add(buttonExit);

        javax.swing.GroupLayout toolbarPanelLayout = new javax.swing.GroupLayout(toolbarPanel);
        toolbarPanel.setLayout(toolbarPanelLayout);
        toolbarPanelLayout.setHorizontalGroup(
            toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolbarPanelLayout.createSequentialGroup()
                .addGroup(toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(toolbar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(toolbar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        toolbarPanelLayout.setVerticalGroup(
            toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolbarPanelLayout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(toolbar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(toolbar2, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(121, Short.MAX_VALUE))
        );

        mainPanel.add(toolbarPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 70, -1));

        table1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        table1.getTableHeader().setReorderingAllowed(false);
        scrollPane.setViewportView(table1);

        mainPanel.add(scrollPane, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 40, 770, 370));

        topPanel.setPreferredSize(new java.awt.Dimension(790, 490));

        toolbar3.setBorder(null);
        toolbar3.setFloatable(false);
        toolbar3.setRollover(true);
        toolbar3.setOpaque(false);
        toolbar3.setVerifyInputWhenFocusTarget(false);

        buttonGroup1.add(employeeButton);
        employeeButton.setText("Employees");
        employeeButton.setContentAreaFilled(false);
        employeeButton.setFocusable(false);
        employeeButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        employeeButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                employeeButtonMouseClicked(evt);
            }
        });
        toolbar3.add(employeeButton);

        buttonGroup1.add(jobButton);
        jobButton.setText("Job List");
        jobButton.setContentAreaFilled(false);
        jobButton.setFocusable(false);
        jobButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jobButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jobButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jobButtonMouseClicked(evt);
            }
        });
        toolbar3.add(jobButton);

        buttonGroup1.add(branchButton);
        branchButton.setText("Branches");
        branchButton.setContentAreaFilled(false);
        branchButton.setFocusable(false);
        branchButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        branchButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        branchButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                branchButtonMouseClicked(evt);
            }
        });
        toolbar3.add(branchButton);

        toolbar4.setBorder(null);
        toolbar4.setFloatable(false);
        toolbar4.setRollover(true);
        toolbar4.setOpaque(false);

        searchButton.setText("Search");
        searchButton.setFocusable(false);
        searchButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        searchButton.setMaximumSize(new java.awt.Dimension(70, 20));
        searchButton.setMinimumSize(new java.awt.Dimension(70, 20));
        searchButton.setPreferredSize(new java.awt.Dimension(70, 20));
        searchButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolbar4.add(searchButton);

        searchField.setFont(new java.awt.Font("Ubuntu", 2, 12));
        searchField.setText("Enter Keyword");
        searchField.setMaximumSize(new java.awt.Dimension(200, 20));
        searchField.setMinimumSize(new java.awt.Dimension(200, 20));
        searchField.setPreferredSize(new java.awt.Dimension(200, 20));
        searchField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                searchFieldFocusGained(evt);
            }
        });
        searchField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchFieldKeyReleased(evt);
            }
        });
        toolbar4.add(searchField);

        javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel);
        topPanel.setLayout(topPanelLayout);
        topPanelLayout.setHorizontalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup()
                .addComponent(toolbar3, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(497, Short.MAX_VALUE))
            .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(topPanelLayout.createSequentialGroup()
                    .addContainerGap(519, Short.MAX_VALUE)
                    .addComponent(toolbar4, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        topPanelLayout.setVerticalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolbar3, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
            .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(toolbar4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE))
        );

        mainPanel.add(topPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 0, 790, 40));

        bottomPanel.setBorder(null);
        bottomPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        saveButton2.setText("Save");
        saveButton2.setEnabled(false);
        saveButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveButton2MouseClicked(evt);
            }
        });

        undoButton.setText("Undo");
        undoButton.setEnabled(false);
        undoButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                undoButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
        buttonPanel.setLayout(buttonPanelLayout);
        buttonPanelLayout.setHorizontalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(saveButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .addComponent(undoButton, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE))
                .addContainerGap())
        );
        buttonPanelLayout.setVerticalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonPanelLayout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addComponent(saveButton2)
                .addGap(26, 26, 26)
                .addComponent(undoButton)
                .addContainerGap(46, Short.MAX_VALUE))
        );

        bottomPanel.add(buttonPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(640, 0, -1, -1));

        panel.setBorder(javax.swing.BorderFactory.createTitledBorder("New"));
        panel.setEnabled(false);

        labelName.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelName.setText("Name");

        labelJob.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelJob.setText("Job");

        labelBranch.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelBranch.setText("Branch");

        labelContactNumber.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelContactNumber.setText("Contact Number");

        labelAddress.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelAddress.setText("Address");

        labelEqual1.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelEqual1.setText(":");

        labelEqual2.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelEqual2.setText(":");

        labelEqual3.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelEqual3.setText(":");

        labelEqual4.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelEqual4.setText(":");

        labelEqual5.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelEqual5.setText(":");

        nameField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nameFieldKeyTyped(evt);
            }
        });

        contactNumberField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                contactNumberFieldKeyTyped(evt);
            }
        });

        addressField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                addressField1KeyTyped(evt);
            }
        });

        addressField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                addressField2KeyTyped(evt);
            }
        });

        jobDropDownMenu.setFont(new java.awt.Font("Ubuntu", 0, 12));
        jobDropDownMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jobDropDownMenuActionPerformed(evt);
            }
        });

        branchDropDownMenu.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchDropDownMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                branchDropDownMenuActionPerformed(evt);
            }
        });

        labelName1.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelName1.setText("ID");

        labelEqual12.setFont(new java.awt.Font("Ubuntu", 0, 12));
        labelEqual12.setText(":");

        jLabel1.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N

        javax.swing.GroupLayout employeePanelLayout = new javax.swing.GroupLayout(employeePanel);
        employeePanel.setLayout(employeePanelLayout);
        employeePanelLayout.setHorizontalGroup(
            employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(employeePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelName)
                    .addComponent(labelJob)
                    .addComponent(labelBranch)
                    .addComponent(labelName1))
                .addGap(18, 18, 18)
                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(labelEqual12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(labelEqual3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(labelEqual2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(labelEqual1, javax.swing.GroupLayout.DEFAULT_SIZE, 5, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(employeePanelLayout.createSequentialGroup()
                        .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(jobDropDownMenu, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(branchDropDownMenu, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(employeePanelLayout.createSequentialGroup()
                                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(labelAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelContactNumber))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(labelEqual5, javax.swing.GroupLayout.DEFAULT_SIZE, 13, Short.MAX_VALUE)
                                    .addComponent(labelEqual4, javax.swing.GroupLayout.DEFAULT_SIZE, 13, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(contactNumberField, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                                    .addComponent(addressField1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(addressField2, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)))
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        employeePanelLayout.setVerticalGroup(
            employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, employeePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelName1)
                    .addComponent(labelEqual12)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(employeePanelLayout.createSequentialGroup()
                        .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelName)
                            .addComponent(labelEqual1)
                            .addComponent(labelContactNumber)
                            .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelJob)
                            .addComponent(labelEqual2)
                            .addComponent(jobDropDownMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelAddress)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, employeePanelLayout.createSequentialGroup()
                        .addComponent(labelEqual4, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(labelEqual5, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE))
                    .addGroup(employeePanelLayout.createSequentialGroup()
                        .addComponent(contactNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                        .addComponent(addressField1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(employeePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(labelBranch)
                        .addComponent(labelEqual3)
                        .addComponent(branchDropDownMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(addressField2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        branchNoLabel.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchNoLabel.setText("Branch No");

        branchNameLabel.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchNameLabel.setText("Branch Name");

        branchAddressLabel.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchAddressLabel.setText("Branch Address");

        branchNoField.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchNoField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                branchNoFieldKeyTyped(evt);
            }
        });

        branchNameField.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchNameField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                branchNameFieldKeyTyped(evt);
            }
        });

        branchAddressField1.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchAddressField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                branchAddressField1KeyTyped(evt);
            }
        });

        branchAddressField2.setFont(new java.awt.Font("Ubuntu", 0, 12));
        branchAddressField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                branchAddressField2KeyTyped(evt);
            }
        });

        labelEqual9.setText(":");

        labelEqual10.setText(":");

        labelEqual11.setText(":");

        javax.swing.GroupLayout branchPanelLayout = new javax.swing.GroupLayout(branchPanel);
        branchPanel.setLayout(branchPanelLayout);
        branchPanelLayout.setHorizontalGroup(
            branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, branchPanelLayout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(branchAddressField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(branchPanelLayout.createSequentialGroup()
                        .addGroup(branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(branchNoLabel)
                            .addComponent(branchAddressLabel))
                        .addGap(8, 8, 8)
                        .addGroup(branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(labelEqual9, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelEqual10, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(branchPanelLayout.createSequentialGroup()
                                .addComponent(branchNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(49, 49, 49)
                                .addComponent(branchNameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(labelEqual11, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(branchNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(branchAddressField1, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE))))
                .addGap(35, 35, 35))
        );
        branchPanelLayout.setVerticalGroup(
            branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(branchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(branchNoLabel)
                    .addComponent(branchNameLabel)
                    .addComponent(branchNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(branchNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelEqual9)
                    .addComponent(labelEqual11))
                .addGroup(branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, branchPanelLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(branchAddressField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(branchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(branchAddressLabel)
                        .addComponent(labelEqual10)))
                .addGap(18, 18, 18)
                .addComponent(branchAddressField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jobNoLabel.setFont(new java.awt.Font("Ubuntu", 0, 12));
        jobNoLabel.setText("Job No");

        jobNameLabel.setFont(new java.awt.Font("Ubuntu", 0, 12));
        jobNameLabel.setText("Job Name");

        salaryLabel.setFont(new java.awt.Font("Ubuntu", 0, 12));
        salaryLabel.setText("Salary");

        labelEqual6.setText(":");

        labelEqual7.setText(":");

        labelEqual8.setText(":");

        jobNoField.setFont(new java.awt.Font("Ubuntu", 0, 12));
        jobNoField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jobNoFieldKeyTyped(evt);
            }
        });

        jobNameField.setFont(new java.awt.Font("Ubuntu", 0, 12));
        jobNameField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jobNameFieldKeyTyped(evt);
            }
        });

        salaryField.setFont(new java.awt.Font("Ubuntu", 0, 12));
        salaryField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                salaryFieldKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jobPanelLayout = new javax.swing.GroupLayout(jobPanel);
        jobPanel.setLayout(jobPanelLayout);
        jobPanelLayout.setHorizontalGroup(
            jobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jobPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jobNoLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jobNameLabel, javax.swing.GroupLayout.Alignment.LEADING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jobPanelLayout.createSequentialGroup()
                        .addComponent(labelEqual6, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jobNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE)
                        .addComponent(salaryLabel)
                        .addGap(18, 18, 18)
                        .addComponent(labelEqual8, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(salaryField, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jobPanelLayout.createSequentialGroup()
                        .addComponent(labelEqual7, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jobNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(306, 306, 306)))
                .addGap(31, 31, 31))
        );
        jobPanelLayout.setVerticalGroup(
            jobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jobPanelLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jobNoLabel)
                    .addComponent(salaryLabel)
                    .addComponent(labelEqual6)
                    .addComponent(labelEqual8)
                    .addComponent(jobNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(salaryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jobPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jobNameLabel)
                    .addComponent(labelEqual7)
                    .addComponent(jobNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(employeePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jobPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(branchPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(employeePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelLayout.createSequentialGroup()
                    .addComponent(jobPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
            .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(branchPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bottomPanel.add(panel, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 20, 590, 170));

        mainPanel.add(bottomPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 410, 770, 190));

        mainPanel.setBounds(0, 0, 840, 600);
        mainLayeredPane.add(mainPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(mainLayeredPane, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 840, 600));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void employeeButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_employeeButtonMouseClicked
        if (!searchField.getText().equals("Enter Keyword")){
            searchField.setText("");
        }
        getTableInfo();
        setTable();
        addAndEdit();
    }//GEN-LAST:event_employeeButtonMouseClicked

    private void branchButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_branchButtonMouseClicked
        if (!searchField.getText().equals("Enter Keyword")){
            searchField.setText("");
        }
        getTableInfo();
        setTable();
        addAndEdit();
    }//GEN-LAST:event_branchButtonMouseClicked

    private void jobButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jobButtonMouseClicked
        if (!searchField.getText().equals("Enter Keyword")){
            searchField.setText("");
        }
        getTableInfo();
        setTable();
        addAndEdit();
    }//GEN-LAST:event_jobButtonMouseClicked

    private void buttonNewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonNewMouseClicked
        panel.setBorder(javax.swing.BorderFactory.createTitledBorder("New"));
        selectMode = 0;
        table1.clearSelection();
        clearFields();
        disableSaveAndUndoButton();
        addAndEdit();
    }//GEN-LAST:event_buttonNewMouseClicked

    private void buttonEditMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonEditMouseClicked
        panel.setBorder(javax.swing.BorderFactory.createTitledBorder("Edit"));
        selectMode = 1;
        if (table1.getSelectedRow() != -1){
            table1.clearSelection();
            clearFields();
            addAndEdit();
            disableSaveAndUndoButton();
        }
    }//GEN-LAST:event_buttonEditMouseClicked

    private void nameFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nameFieldKeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_nameFieldKeyTyped

    private void contactNumberFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_contactNumberFieldKeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_contactNumberFieldKeyTyped

    private void addressField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_addressField1KeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_addressField1KeyTyped

    private void addressField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_addressField2KeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_addressField2KeyTyped

    private void jobDropDownMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jobDropDownMenuActionPerformed
        enableSaveAndUndoButton();
    }//GEN-LAST:event_jobDropDownMenuActionPerformed

    private void saveButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveButton2MouseClicked
        confirmationMessage();
        disableSaveAndUndoButton();
    }//GEN-LAST:event_saveButton2MouseClicked

    private void undoButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_undoButtonMouseClicked
        getRecordInfo();
    }//GEN-LAST:event_undoButtonMouseClicked

    private void buttonSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonSaveMouseClicked
        confirmationMessage();
    }//GEN-LAST:event_buttonSaveMouseClicked

    private void butttonDeleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_butttonDeleteMouseClicked
        confirmationDelete();
    }//GEN-LAST:event_butttonDeleteMouseClicked

    private void buttonLogoutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonLogoutMouseClicked
        mainMenu windowMainMenu = new mainMenu();
        windowMainMenu.show();
        this.dispose();
    }//GEN-LAST:event_buttonLogoutMouseClicked

    private void buttonExitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonExitMouseClicked
       this.dispose();
    }//GEN-LAST:event_buttonExitMouseClicked

    private void jobNoFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jobNoFieldKeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_jobNoFieldKeyTyped

    private void jobNameFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jobNameFieldKeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_jobNameFieldKeyTyped

    private void salaryFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_salaryFieldKeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_salaryFieldKeyTyped

    private void branchNoFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_branchNoFieldKeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_branchNoFieldKeyTyped

    private void branchNameFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_branchNameFieldKeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_branchNameFieldKeyTyped

    private void branchAddressField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_branchAddressField1KeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_branchAddressField1KeyTyped

    private void branchAddressField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_branchAddressField2KeyTyped
        enableSaveAndUndoButton();
    }//GEN-LAST:event_branchAddressField2KeyTyped

    private void branchDropDownMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_branchDropDownMenuActionPerformed
        enableSaveAndUndoButton();
    }//GEN-LAST:event_branchDropDownMenuActionPerformed

    private void searchFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchFieldKeyReleased
        searchSQL();
    }//GEN-LAST:event_searchFieldKeyReleased

    private void searchFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_searchFieldFocusGained
        if (searchField.getText().equals("Enter Keyword")){
            searchField.setText("");
        }
    }//GEN-LAST:event_searchFieldFocusGained

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new humanResourceModule().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField addressField1;
    private javax.swing.JTextField addressField2;
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JTextField branchAddressField1;
    private javax.swing.JTextField branchAddressField2;
    private javax.swing.JLabel branchAddressLabel;
    private javax.swing.JRadioButton branchButton;
    private javax.swing.JComboBox branchDropDownMenu;
    private javax.swing.JTextField branchNameField;
    private javax.swing.JLabel branchNameLabel;
    private javax.swing.JTextField branchNoField;
    private javax.swing.JLabel branchNoLabel;
    private javax.swing.JPanel branchPanel;
    private javax.swing.JButton buttonEdit;
    private javax.swing.JButton buttonExit;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton buttonLogout;
    private javax.swing.JButton buttonNew;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton buttonSave;
    private javax.swing.JButton butttonDelete;
    private javax.swing.JTextField contactNumberField;
    private javax.swing.JRadioButton employeeButton;
    private javax.swing.JPanel employeePanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButton jobButton;
    private javax.swing.JComboBox jobDropDownMenu;
    private javax.swing.JTextField jobNameField;
    private javax.swing.JLabel jobNameLabel;
    private javax.swing.JTextField jobNoField;
    private javax.swing.JLabel jobNoLabel;
    private javax.swing.JPanel jobPanel;
    private javax.swing.JLabel labelAddress;
    private javax.swing.JLabel labelBranch;
    private javax.swing.JLabel labelContactNumber;
    private javax.swing.JLabel labelEqual1;
    private javax.swing.JLabel labelEqual10;
    private javax.swing.JLabel labelEqual11;
    private javax.swing.JLabel labelEqual12;
    private javax.swing.JLabel labelEqual2;
    private javax.swing.JLabel labelEqual3;
    private javax.swing.JLabel labelEqual4;
    private javax.swing.JLabel labelEqual5;
    private javax.swing.JLabel labelEqual6;
    private javax.swing.JLabel labelEqual7;
    private javax.swing.JLabel labelEqual8;
    private javax.swing.JLabel labelEqual9;
    private javax.swing.JLabel labelJob;
    private javax.swing.JLabel labelName;
    private javax.swing.JLabel labelName1;
    private javax.swing.JLayeredPane mainLayeredPane;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTextField nameField;
    private javax.swing.JPanel panel;
    private javax.swing.JTextField salaryField;
    private javax.swing.JLabel salaryLabel;
    private javax.swing.JButton saveButton2;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JButton searchButton;
    private javax.swing.JTextField searchField;
    private javax.swing.JTable table1;
    private javax.swing.JToolBar toolbar1;
    private javax.swing.JToolBar toolbar2;
    private javax.swing.JToolBar toolbar3;
    private javax.swing.JToolBar toolbar4;
    private javax.swing.JPanel toolbarPanel;
    private javax.swing.JPanel topPanel;
    private javax.swing.JButton undoButton;
    // End of variables declaration//GEN-END:variables


    //myVariables
    Connection con;
    NewTableModel newTableEmployee = new NewTableModel();
    NewTableModel newTableJob = new NewTableModel();
    NewTableModel newTableBranch = new NewTableModel();
    int countTable1Row = 0;
    int countTable1Column = 0;
    int countTable2Row = 0;
    int countTable2Column = 0;
    int countTable3Row = 0;
    int countTable3Column = 0;
    int rowIncrement = 0;
    int columnIncrement = 0;
    String[] jobMenuItem;
    String[] branchMenuItem;
    int selectMode = 0;

    public void initDatabase(){
        try{
            DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
            con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "Edwind", "cat200");
            System.out.println("Database Connected");
        }
        catch(Exception e){
            System.out.println("Cannot connect to database");
        }
    }

    public void getTableInfo(){


        Dimension THIS_SIZE = (mainLayeredPane.getSize());

        table1.setMaximumSize(THIS_SIZE);
        table1.setMinimumSize(THIS_SIZE);
        table1.setPreferredSize(THIS_SIZE);

        countTable1Row = 0;
        countTable1Column = 0;
        countTable2Row = 0;
        countTable2Column = 0;
        countTable3Row = 0;
        countTable3Column = 0;
        rowIncrement = 0;
        columnIncrement = 0;


        try{
            Statement stmt = con.createStatement();
            ResultSet rset = stmt.executeQuery("SELECT* FROM EMPLOYEE");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable1Row++;
            }

            ResultSetMetaData metadata = rset.getMetaData();
            countTable1Column = metadata.getColumnCount();

            newTableEmployee.setDataSize(countTable1Row, countTable1Column);
            newTableEmployee.setColumnNameSize();
            //end

            //adding column names to table model
            newTableEmployee.setColumnName(0, "Employee ID");
            newTableEmployee.setColumnName(1, "Name");
            newTableEmployee.setColumnName(2, "Job");
            newTableEmployee.setColumnName(3, "Branch");
            newTableEmployee.setColumnName(4, "Contact No.");
            newTableEmployee.setColumnName(5, "Address");
            // end

            rset = stmt.executeQuery("SELECT* FROM EMPLOYEE");
            while(rset.next()){
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_ID"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_NAME"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("JOB_NO"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("BRANCH_NO"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_CONTACT_NO"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_ADDRESS"));
                columnIncrement = 0;
                rowIncrement++;
            }

            rowIncrement = 0;
            columnIncrement = 0;

            rset = stmt.executeQuery("SELECT* FROM JOB");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable2Row++;
            }

            metadata = rset.getMetaData();
            countTable2Column = metadata.getColumnCount();

            newTableJob.setDataSize(countTable2Row, countTable2Column);
            newTableJob.setColumnNameSize();
            //end

            //adding column names to table model
            newTableJob.setColumnName(0, "Job ID");
            newTableJob.setColumnName(1, "Job Description");
            newTableJob.setColumnName(2, "Salary");
            // end

            rset = stmt.executeQuery("SELECT* FROM JOB");
            while(rset.next()){
                newTableJob.addString(rowIncrement, columnIncrement, rset.getString("JOB_NO"));
                columnIncrement++;
                newTableJob.addString(rowIncrement, columnIncrement, rset.getString("JOB_NAME"));
                columnIncrement++;
                newTableJob.addString(rowIncrement, columnIncrement, rset.getString("JOB_SALARY"));
                columnIncrement = 0;
                rowIncrement++;
            }

            rowIncrement = 0;
            columnIncrement = 0;

            rset = stmt.executeQuery("SELECT* FROM BRANCH");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable3Row++;
            }

            metadata = rset.getMetaData();
            countTable3Column = metadata.getColumnCount();

            newTableBranch.setDataSize(countTable3Row, countTable3Column);
            newTableBranch.setColumnNameSize();
            //end

            //adding column names to table model
            newTableBranch.setColumnName(0, "Branch No.");
            newTableBranch.setColumnName(1, "Branch Name");
            newTableBranch.setColumnName(2, "Branch Address");
            // end

            rset = stmt.executeQuery("SELECT* FROM BRANCH");
            while(rset.next()){
                newTableBranch.addString(rowIncrement, columnIncrement, rset.getString("BRANCH_NO"));
                columnIncrement++;
                newTableBranch.addString(rowIncrement, columnIncrement, rset.getString("BRANCH_NAME"));
                columnIncrement++;
                newTableBranch.addString(rowIncrement, columnIncrement, rset.getString("BRANCH_ADDRESS"));
                columnIncrement = 0;
                rowIncrement++;
            }
        }
        catch(Exception e){
            System.out.println("Error connecting database");
        }
    }

    public void setTable(){

        setComboBoxes();
        table1.setModel(selectedTable());
        table1.show();

        ListSelectionModel selectionModel = table1.getSelectionModel();

            selectionModel.addListSelectionListener(new ListSelectionListener(){

            public void valueChanged(ListSelectionEvent e) {
                if (table1.getSelectedRow() != -1){
                    panel.setBorder(javax.swing.BorderFactory.createTitledBorder("Edit"));
                    selectMode = 1;
                    getRecordInfo();
                    disableSaveAndUndoButton();
                    addAndEdit();
                }
            }
        }
        );

    }

    public NewTableModel selectedTable(){

        int n = selectedButton();
        if (n == 0){
            return newTableEmployee;
        }
        else if (n == 1){
            return newTableJob;
        }

        return newTableBranch;
    }

   public int selectedButton(){

        if (employeeButton.isSelected()){
            System.out.print("Employee Table Selected\n");
            return 0;
        }
        else if (jobButton.isSelected()){
            System.out.print("Job Table Selected\n");
            return 1;
        }

        System.out.print("Branch Table Selected\n");
        return 2;
    }

    public void getRecordInfo(){

        int tableChoice = selectedButton();

        int i = 0;

        if (tableChoice == 0){
            int spaces = 0;
            String tempString1 = "";
            String tempString2 = "";
            String address = (String) newTableEmployee.getValueAt(table1.getSelectedRow(), 5);
            int addressLength = address.length();
            int jobIndex = 0;
            int branchIndex = 0;

            for (i = 0; i < addressLength; i++){
                tempString1 = tempString1 + address.charAt(i);
                if (address.charAt(i) == ' '){
                    spaces++;
                }

                if (spaces == 4){
                    break;
                }
            }

            for (; i < addressLength; i++){
                tempString2 = tempString2 + address.charAt(i);
            }

            for (i = 0; i < countTable2Row; i++){
                if (newTableEmployee.getValueAt(table1.getSelectedRow(), 2).equals(newTableJob.getValueAt(i,0))){
                    jobIndex = i;
                }
            }

            for (i = 0; i < countTable3Row; i++){
                if (newTableEmployee.getValueAt(table1.getSelectedRow(), 3).equals(newTableBranch.getValueAt(i,0))){
                    branchIndex = i;
                }
            }

            jLabel1.setText((String) newTableEmployee.getValueAt(table1.getSelectedRow(), 0));
            nameField.setText((String) newTableEmployee.getValueAt(table1.getSelectedRow(), 1));
            jobDropDownMenu.setSelectedIndex(jobIndex);
            branchDropDownMenu.setSelectedIndex(branchIndex);
            //drop down menus index starts with 0
            contactNumberField.setText((String) newTableEmployee.getValueAt(table1.getSelectedRow(), 4));
            addressField1.setText(tempString1);
            addressField2.setText(tempString2);
        }
        else if (tableChoice == 1){
            jobNoField.setText((String) newTableJob.getValueAt(table1.getSelectedRow(), 0));
            jobNameField.setText((String) newTableJob.getValueAt(table1.getSelectedRow(), 1));
            salaryField.setText((String) newTableJob.getValueAt(table1.getSelectedRow(), 2));
        }
        else if (tableChoice == 2){
            int spaces = 0;
            String tempString1 = "";
            String tempString2 = "";
            String address = (String) newTableBranch.getValueAt(table1.getSelectedRow(), 2);
            int addressLength = address.length();

            for (i = 0; i < addressLength; i++){
                tempString1 = tempString1 + address.charAt(i);
                if (address.charAt(i) == ' '){
                    spaces++;
                }

                if (spaces == 6){
                    break;
                }
            }

            for (; i < addressLength; i++){
                tempString2 = tempString2 + address.charAt(i);
            }

            branchNoField.setText((String) newTableBranch.getValueAt(table1.getSelectedRow(), 0));
            branchNameField.setText((String) newTableBranch.getValueAt(table1.getSelectedRow(), 1));
            branchAddressField1.setText(tempString1);
            branchAddressField2.setText(tempString2);
        }
    }

    public void clearFields(){
        jLabel1.setText("");
        nameField.setText("");
        contactNumberField.setText("");
        addressField1.setText("");
        addressField2.setText("");
        jobDropDownMenu.setSelectedIndex(0);
        branchDropDownMenu.setSelectedIndex(0);
        jobNoField.setText("");
        jobNameField.setText("");
        salaryField.setText("");
        branchNoField.setText("");
        branchNameField.setText("");
        branchAddressField1.setText("");
        branchAddressField2.setText("");

    }

    public void addAndEdit(){
        int tableChoice = selectedButton();
        if (tableChoice == 0){
            employeePanel.setVisible(true);
            jobPanel.setVisible(false);
            branchPanel.setVisible(false);
            nameField.requestFocus();
        }
        else if (tableChoice == 1){
            jobPanel.setVisible(true);
            employeePanel.setVisible(false);
            branchPanel.setVisible(false);
            jobNoField.requestFocus();
        }
        else if (tableChoice == 2){
            branchPanel.setVisible(true);
            jobPanel.setVisible(false);
            employeePanel.setVisible(false);
            branchNoField.requestFocus();
        }
    }

    public void setComboBoxes(){
        setJobDropDownMenu();
        setBranchDropDownMenu();
    }

    public void setJobDropDownMenu(){

        jobDropDownMenu.removeAllItems();

        int countJobTableRow = 0;
        int i = 0;

        try{
            Statement stmt = con.createStatement();
            ResultSet rset = stmt.executeQuery("SELECT JOB_NAME FROM JOB");

            while (rset.next()){
                countJobTableRow++;
            }

            jobMenuItem = new String[countJobTableRow];

            rset = stmt.executeQuery("SELECT JOB_NAME FROM JOB");

            while (rset.next()){
                jobMenuItem[i] = rset.getString("JOB_NAME");
                i++;
            }

            i = 0;

            for (i = 0; i < countJobTableRow; i++){
                jobDropDownMenu.addItem(jobMenuItem[i]);
            }

        }
        catch (Exception e){
            System.out.println("Error connecting database");
        }
    }
    
    public void setBranchDropDownMenu(){

        branchDropDownMenu.removeAllItems();

        int countBranchTableRow = 0;
        int i = 0;

        try{
            Statement stmt = con.createStatement();
            ResultSet rset = stmt.executeQuery("SELECT BRANCH_NAME FROM BRANCH");

            while (rset.next()){
                countBranchTableRow++;
            }

            branchMenuItem = new String[countBranchTableRow];

            rset = stmt.executeQuery("SELECT BRANCH_NAME FROM BRANCH");

            while (rset.next()){
                branchMenuItem[i] = rset.getString("BRANCH_NAME");
                i++;
            }

            i = 0;

            for (i = 0; i < countBranchTableRow; i++){
                branchDropDownMenu.addItem(branchMenuItem[i]);
            }

        }
        catch (Exception e){
            System.out.println("Error connecting database");
        }
    }

    public void enableSaveAndUndoButton(){
        saveButton2.setEnabled(true);
        undoButton.setEnabled(true);
    }

    public void disableSaveAndUndoButton(){
        saveButton2.setEnabled(false);
        undoButton.setEnabled(false);
    }

    public void confirmationMessage(){
        Object[] options = {"Yes", "Cancel"};

        int n = JOptionPane.showOptionDialog(this,
                "Saving this data will permanently change your data.Do you want to continue?",
                "Confirmation",//title
                JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE,
                null,        //custom icon
                options,     //the titles of buttons
                options[0]); //default button

        if (n == 0){
            save();
        }
    }

    public int promptSaveBeforeExit(){
        Object[] options = {"Yes", "Discard", "Cancel"};

        int n = JOptionPane.showOptionDialog(this,
                "Some information have changed. If you continue you will lose all unsaved changes.",
                "Confirmation",//title
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null,        //custom icon
                options,     //the titles of buttons
                options[0]); //default button

        return n;
    }

    public void confirmationDelete(){
        Object[] options = {"Yes", "Cancel"};

        int n = JOptionPane.showOptionDialog(this,
                "Data deleted will be permanently gone.Do you want to continue?",
                "Confirmation",//title
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null,        //custom icon
                options,     //the titles of buttons
                options[0]); //default button

        if (n == 0){
            delete();
        }
    }
    
    public void errorMessage(){

        JOptionPane.showMessageDialog(this,
                "An error has occured. Data cannot be deleted.",
                "Warning",//title
                JOptionPane.WARNING_MESSAGE,
                null);
    }
    
    public void errorMessage2(){

        JOptionPane.showMessageDialog(this,
                "The job number already exists. Data cannot be saved.",
                "Warning",//title
                JOptionPane.WARNING_MESSAGE,
                null);
    }


    public void errorMessage3(){

        JOptionPane.showMessageDialog(this,
                "The branch number/name already exists. Data cannot be saved.",
                "Warning",//title
                JOptionPane.WARNING_MESSAGE,
                null);
    }

    public void errorMessage4(){

        JOptionPane.showMessageDialog(this,
                "The job/branch number currently exists in Employees data. Data cannot be deleted.",
                "Warning",//title
                JOptionPane.WARNING_MESSAGE,
                null);
    }

    public void save(){
        int n = selectedButton();
        String updateString = "";

        if (n == 0){//employee table
            String jobCode = (String)newTableJob.getValueAt(jobDropDownMenu.getSelectedIndex(), 0);
            String branchCode = (String)newTableBranch.getValueAt(branchDropDownMenu.getSelectedIndex(), 0);

            if (selectMode == 0){//insert new row
                if (!validation_employee_save()){
                    return;
                }
                else if (validation_employee_save()){
                    updateString = "INSERT INTO EMPLOYEE VALUES ('" + (countTable1Row + 1)
                    + "','" + nameField.getText() + "','" + jobCode
                    + "','" + branchCode
                    + "','" + contactNumberField.getText() + "','" + addressField1.getText() + addressField2.getText()
                    + "')";
                }
            }
            else if (selectMode == 1){//update existing row
                if (!validation_employee_save()){
                    return;
                }
                else if (validation_employee_save()){
                    updateString = "UPDATE EMPLOYEE SET EMP_NAME = '" + nameField.getText()
                        + "', JOB_NO = '" + jobCode
                        + "', BRANCH_NO = '" + branchCode
                        + "', EMP_CONTACT_NO = '" + contactNumberField.getText()
                        + "', EMP_ADDRESS = '" + addressField1.getText() + addressField2.getText()
                        + "' WHERE EMP_ID = '" + (newTableEmployee.getValueAt(table1.getSelectedRow(), 0)) + "'";
                }
            }
        }
        else if (n == 1){//job table
            if (selectMode == 0){//insert new row
                if (!validation_job_save()){
                    return;
                }
                else if (validation_job_save()){
                    updateString = "INSERT INTO JOB VALUES ('" + jobNoField.getText()
                        + "','" + jobNameField.getText()
                        + "','" + salaryField.getText() + "')";
                }
            }
            else if (selectMode == 1){//update existing row
                if (!validation_job_save()){
                    return;
                }
                else if (validation_job_save()){
                    updateString = "UPDATE JOB SET JOB_NO = '" + jobNoField.getText() + "', JOB_NAME = '" + jobNameField.getText()
                        + "', JOB_SALARY = '" + salaryField.getText()
                        + "' WHERE JOB_NO = '" + (newTableJob.getValueAt(table1.getSelectedRow(), 0)) + "'";
                }
            }
        }
        else if (n == 2){//branch table
            if (selectMode == 0){//insert new row
                if (!validation_branch_save()){
                    return;
                }
                else if (validation_branch_save()){
                    updateString = "INSERT INTO BRANCH VALUES ('" + branchNoField.getText()
                    + "','" + branchNameField.getText()
                    + "','" + branchAddressField1.getText() + branchAddressField2.getText() +"')";
                }
            }
            else if (selectMode == 1){//update existing row
                if (!validation_branch_save()){
                    return;
                }
                else if (validation_branch_save()){
                updateString = "UPDATE BRANCH SET BRANCH_NAME = '" + branchNameField.getText()
                        + "', BRANCH_ADDRESS = '" + branchAddressField1.getText()+ branchAddressField2.getText()
                        + "' WHERE BRANCH_NO = '" + branchNoField.getText() + "'";
                }
            }
        }
        
        System.out.println(updateString);

        try{
            Statement stmt = con.createStatement();
            stmt.executeUpdate(updateString);
        }
        catch (Exception e){
            System.out.print("Error connecting to Database\n");
        }
        
        if (!searchField.getText().equals("Enter Keyword")&&!searchField.getText().equals(""))
        {
            searchSQL();
            clearFields();
        }
        else {
            getTableInfo();
            setTable();
            clearFields();
            table1.repaint();
        }
    }

    public void delete(){
        
        int n = selectedButton();
        String deleteString = "";
        
        if (table1.getSelectedRow() != -1 ){
            if (n == 0){
                if (!validation_employee_delete()){
                    return;
                }
                else if (validation_employee_delete()){
                    deleteString =  "DELETE FROM EMPLOYEE WHERE EMP_ID = '" + newTableEmployee.getValueAt(table1.getSelectedRow(), 0) + "'";
                }
            }
            else if (n == 1){
                if (!validation_job_delete()){
                    return;
                }
                else if (validation_job_delete()){
                    deleteString = "DELETE FROM JOB WHERE JOB_NO = '" + jobNoField.getText() + "'";
                }
            }
            else if (n == 2){
                if (!validation_branch_delete()){
                    return;
                }
                else if (validation_branch_delete()){
                    deleteString = "DELETE FROM BRANCH WHERE BRANCH_NO = '" + branchNoField.getText() + "'";
                }
            }
        }

        System.out.println(deleteString);

        try{
            Statement stmt = con.createStatement();
            stmt.executeUpdate(deleteString);
        }
        catch (Exception e){
            errorMessage();
        }

        if (!searchField.getText().equals("Enter Keyword")&&!searchField.getText().equals(""))
        {
            searchSQL();
            clearFields();
            disableSaveAndUndoButton();
        }
        else {
            getTableInfo();
            setTable();
            clearFields();
            disableSaveAndUndoButton();
            table1.repaint();
        }
    }

    public boolean validation_employee_save(){//currently no validation for employee table
        return true;
    }

    public boolean validation_job_save(){
        for (int i = 0; i < countTable2Row; i++){
            
            if ((selectMode == 1) && (i == table1.getSelectedRow())){//skip from comparing with itself
                i++;
            }

            if ((i < countTable2Row) && (jobNoField.getText().equals(newTableJob.getValueAt(i, 0)))){
                errorMessage2();
                return false;
            }
        }

        return true;
    }

    public boolean validation_branch_save(){
        for (int i = 0; i < countTable3Row; i++){
            if ((selectMode == 1) && (i == table1.getSelectedRow())){//skip from comparing with itself
                i++;
            }

            if ((i < countTable3Row) && (branchNoField.getText().equals(newTableBranch.getValueAt(i, 0)))){
                errorMessage3();
                return false;
            }
        }

        for (int i = 0; i < countTable3Row; i++){
            if ((selectMode == 1) && (i == table1.getSelectedRow())){//skip from comparing with itself
                i++;
            }
            if ((i < countTable3Row) && (branchNameField.getText().equals(newTableBranch.getValueAt(i, 1)))){
                errorMessage3();
                return false;
            }
        }

        return true;
    }

    public boolean validation_employee_delete(){//currently no validation for employee table
        return true;
    }

    public boolean validation_job_delete(){//check whether the job number is being used in employees table
        for (int i = 0; i < countTable1Row; i++){
            if (jobNoField.getText().equals(newTableEmployee.getValueAt(i, 2))){
                errorMessage4();
                return false;
            }
        }
        return true;
    }

    public boolean validation_branch_delete(){//check whether the branch number is being used in employees table
         for (int i = 0; i < countTable1Row; i++){

            if (branchNoField.getText().equals(newTableEmployee.getValueAt(i, 3))){
                errorMessage4();
                return false;
            }
        }

        return true;
    }
    
    public void searchSQL(){
        
        String searchString = "";
        String tempString = searchField.getText();
        int n = selectedButton();


        Dimension THIS_SIZE = (mainLayeredPane.getSize());

        table1.setMaximumSize(THIS_SIZE);
        table1.setMinimumSize(THIS_SIZE);
        table1.setPreferredSize(THIS_SIZE);

        countTable1Row = 0;
        countTable1Column = 0;
        countTable2Row = 0;
        countTable2Column = 0;
        countTable3Row = 0;
        countTable3Column = 0;
        rowIncrement = 0;
        columnIncrement = 0;
        
        if (n == 0){
            
            searchString = "SELECT * FROM EMPLOYEE WHERE EMP_ID LIKE '%" + tempString + "%'"
                + " OR EMP_NAME LIKE '%" + tempString + "%'"
                + " OR JOB_NO LIKE '%" + tempString + "%'"
                + " OR BRANCH_NO LIKE '%" + tempString + "%'"
                + " OR EMP_CONTACT_NO LIKE '%" + tempString + "%'"
                + " OR EMP_ADDRESS LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                Statement stmt = con.createStatement();

                ResultSet rset2 = stmt.executeQuery(searchString);

                //creating 2d arrays of appropriate size according to database
                while (rset2.next()){
                    countTable1Row++;
                }

                ResultSetMetaData metadata = rset2.getMetaData();
                countTable1Column = metadata.getColumnCount();

                newTableEmployee.setDataSize(countTable1Row, countTable1Column);
                newTableEmployee.setColumnNameSize();
                //end

                //adding column names to table model
                newTableEmployee.setColumnName(0, "Employee ID");
                newTableEmployee.setColumnName(1, "Name");
                newTableEmployee.setColumnName(2, "Job");
                newTableEmployee.setColumnName(3, "Branch");
                newTableEmployee.setColumnName(4, "Contact No.");
                newTableEmployee.setColumnName(5, "Address");

                rset2 = stmt.executeQuery(searchString);

                while(rset2.next()){
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_ID"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_NAME"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("JOB_NO"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("BRANCH_NO"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_CONTACT_NO"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_ADDRESS"));
                    columnIncrement = 0;
                    rowIncrement++;
                }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }

        }
        else if (n == 1){
            searchString = "SELECT * FROM JOB WHERE JOB_NO LIKE '%" + tempString + "%'"
                + " OR JOB_NAME LIKE '%" + tempString + "%'"
                + " OR JOB_SALARY LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                Statement stmt = con.createStatement();

                ResultSet rset2 = stmt.executeQuery(searchString);

                //creating 2d arrays of appropriate size according to database
                while (rset2.next()){
                    countTable2Row++;
                }

                ResultSetMetaData metadata = rset2.getMetaData();
                countTable2Column = metadata.getColumnCount();

                newTableJob.setDataSize(countTable2Row, countTable2Column);
                newTableJob.setColumnNameSize();
                //end

                //adding column names to table model
                newTableJob.setColumnName(0, "Job ID");
                newTableJob.setColumnName(1, "Job Description");
                newTableJob.setColumnName(2, "Salary");
                // end

                rset2 = stmt.executeQuery(searchString);

                while(rset2.next()){
                    newTableJob.addString(rowIncrement, columnIncrement, rset2.getString("JOB_NO"));
                    columnIncrement++;
                    newTableJob.addString(rowIncrement, columnIncrement, rset2.getString("JOB_NAME"));
                    columnIncrement++;
                    newTableJob.addString(rowIncrement, columnIncrement, rset2.getString("JOB_SALARY"));
                    columnIncrement = 0;
                    rowIncrement++;
                }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }
        }
        else if (n == 2){
            searchString = "SELECT * FROM BRANCH WHERE BRANCH_NO LIKE '%" + tempString + "%'"
                + " OR BRANCH_NAME LIKE '%" + tempString + "%'"
                + " OR BRANCH_ADDRESS LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                Statement stmt = con.createStatement();

                ResultSet rset2 = stmt.executeQuery(searchString);

                //creating 2d arrays of appropriate size according to database
                while (rset2.next()){
                    countTable3Row++;
                }

                ResultSetMetaData metadata = rset2.getMetaData();
                countTable3Column = metadata.getColumnCount();

                newTableBranch.setDataSize(countTable3Row, countTable3Column);
                newTableBranch.setColumnNameSize();
                //end

                //adding column names to table model
                newTableBranch.setColumnName(0, "Branch No.");
                newTableBranch.setColumnName(1, "Branch Name");
                newTableBranch.setColumnName(2, "Branch Address");
                // end

                rset2 = stmt.executeQuery(searchString);

                while(rset2.next()){
                    newTableBranch.addString(rowIncrement, columnIncrement, rset2.getString("BRANCH_NO"));
                    columnIncrement++;
                    newTableBranch.addString(rowIncrement, columnIncrement, rset2.getString("BRANCH_NAME"));
                    columnIncrement++;
                    newTableBranch.addString(rowIncrement, columnIncrement, rset2.getString("BRANCH_ADDRESS"));
                    columnIncrement = 0;
                    rowIncrement++;
                }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }
        }

        setTable();
        table1.repaint();
        
        
    }
}

